home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / newmat08.zip / NEWMATRC.H < prev    next >
C/C++ Source or Header  |  1995-01-11  |  6KB  |  134 lines

  1. //$$ newmatrc.h              definition file for row/column classes
  2.  
  3. // Copyright (C) 1991,2,3,4: R B Davies
  4.  
  5. #ifndef MATRIXRC_LIB
  6. #define MATRIXRC_LIB 0
  7.  
  8. #include "controlw.h"
  9.  
  10.  
  11.  
  12. /************** classes MatrixRowCol, MatrixRow, MatrixCol *****************/
  13.  
  14. // Used for accessing the rows and columns of matrices
  15. // All matrix classes must provide routines for calculating matrix rows and
  16. // columns. Assume rows can be found very efficiently.
  17.  
  18. enum LSF { LoadOnEntry=1,StoreOnExit=2,IsACopy=4,DirectPart=8,StoreHere=16 };
  19.  
  20.  
  21. class LoadAndStoreFlag : public ControlWord
  22. {
  23. public:
  24.    LoadAndStoreFlag() {}
  25.    LoadAndStoreFlag(int i) : ControlWord(i) {}
  26.    LoadAndStoreFlag(LSF lsf) : ControlWord(lsf) {}
  27.    LoadAndStoreFlag(const ControlWord& cwx) : ControlWord(cwx) {}
  28.    FREE_CHECK(LoadAndStoreFlag)
  29. };
  30.  
  31. class MatrixRowCol
  32. // the row or column of a matrix
  33. {
  34. public:                                        // these are public to avoid
  35.                            // numerous friend statements
  36.    int length;                                 // row or column length
  37.    int skip;                                   // initial number of zeros
  38.    int storage;                                // number of stored elements
  39.    int rowcol;                                 // row or column number
  40.    GeneralMatrix* gm;                          // pointer to parent matrix
  41.    Real* store;                                // pointer to local storage
  42.                            //    less skip
  43.    LoadAndStoreFlag cw;                        // Load? Store? Is a Copy?
  44.    void IncrMat() { rowcol++; store += storage; }
  45.                            // used by NextRow
  46.    void IncrDiag() { rowcol++; skip++; }
  47.    void IncrUT() { rowcol++; storage--; store += storage; skip++; }
  48.    void IncrLT() { rowcol++; store += storage; storage++; }
  49.  
  50. public:
  51.    void Add(const MatrixRowCol&);              // add a row/col
  52.    void AddScaled(const MatrixRowCol&, Real);  // add a multiple of a row/col
  53.    void Add(const MatrixRowCol&, const MatrixRowCol&);
  54.                            // add two rows/cols
  55.    void Add(const MatrixRowCol&, Real);        // add a row/col
  56.    void Sub(const MatrixRowCol&);              // subtract a row/col
  57.    void Sub(const MatrixRowCol&, const MatrixRowCol&);
  58.                            // sub a row/col from another
  59.    void RevSub(const MatrixRowCol&);           // subtract from a row/col
  60.    void ConCat(const MatrixRowCol&, const MatrixRowCol&);
  61.                                                // concatenate two row/cols
  62.    void Multiply(const MatrixRowCol&);         // multiply a row/col
  63.    void Multiply(const MatrixRowCol&, const MatrixRowCol&);
  64.                                                // multiply two row/cols
  65.    void Copy(const MatrixRowCol&);             // copy a row/col
  66.    void CopyCheck(const MatrixRowCol&);        // ... check for data loss
  67.    void Copy(const Real*&);                    // copy from an array
  68.    void Copy(Real);                            // copy from constant
  69.    Real SumAbsoluteValue();                    // sum of absolute values
  70.    Real Sum();                                 // sum of values
  71.    void Inject(const MatrixRowCol&);           // copy stored els of a row/col
  72.    void Negate(const MatrixRowCol&);           // change sign of a row/col
  73.    void Multiply(const MatrixRowCol&, Real);   // scale a row/col
  74.    friend Real DotProd(const MatrixRowCol&, const MatrixRowCol&);
  75.                            // sum of pairwise product
  76.    Real* operator()() { return store+skip; }   // pointer to first element
  77.    Real* Store() { return store; }
  78.    int Skip() { return skip; }                 // number of elements skipped
  79.    int Storage() { return storage; }           // number of elements stored
  80.    int Length() { return length; }             // length of row or column
  81.    void Skip(int i) { skip=i; }
  82.    void Storage(int i) { storage=i; }
  83.    void Length(int i) { length=i; }
  84.    void SubRowCol(MatrixRowCol&, int, int) const;
  85.                            // get part of a row or column
  86.    MatrixRowCol() {}                           // to stop warning messages
  87.    ~MatrixRowCol();
  88.    FREE_CHECK(MatrixRowCol)
  89. };
  90.  
  91. class MatrixRow : public MatrixRowCol
  92. {
  93. public:
  94.    // bodies for these are inline at the end of this .h file
  95.    MatrixRow(GeneralMatrix*, LoadAndStoreFlag, int=0);
  96.                                                // extract a row
  97.    ~MatrixRow();
  98.    void Next();                                // get next row
  99.    FREE_CHECK(MatrixRow)
  100. };
  101.  
  102. class MatrixCol : public MatrixRowCol
  103. {
  104. public:
  105.    // bodies for these are inline at the end of this .h file
  106.    MatrixCol(GeneralMatrix*, LoadAndStoreFlag, int=0);
  107.                                                // extract a col
  108.    MatrixCol(GeneralMatrix*, Real*, LoadAndStoreFlag, int=0);
  109.                                                // store/retrieve a col
  110.    ~MatrixCol();
  111.    void Next();                                // get next row
  112.    FREE_CHECK(MatrixCol)
  113. };
  114.  
  115.  
  116. /**************************** inline bodies ****************************/
  117.  
  118. inline MatrixRow::MatrixRow(GeneralMatrix* gmx, LoadAndStoreFlag cwx, int row)
  119. { gm=gmx; cw=cwx; rowcol=row; gm->GetRow(*this); } 
  120.  
  121. inline void MatrixRow::Next() { gm->NextRow(*this); }
  122.  
  123. inline MatrixCol::MatrixCol(GeneralMatrix* gmx, LoadAndStoreFlag cwx, int col)
  124. { gm=gmx; cw=cwx; rowcol=col; gm->GetCol(*this); } 
  125.  
  126. inline MatrixCol::MatrixCol(GeneralMatrix* gmx, Real* r,
  127.    LoadAndStoreFlag cwx, int col)
  128. { gm=gmx; store=r; cw=cwx+StoreHere; rowcol=col; gm->GetCol(*this); } 
  129.  
  130. inline void MatrixCol::Next() { gm->NextCol(*this); }
  131.  
  132.  
  133. #endif
  134.